#include "PcapMsgTest.h"

#include "Pacap/PcapMsg.h"

#include <memory>


using namespace Pacap;


void PcapMsgTest::SetUpTestCase()
{
    std::cout << "开始PcapMsgTest单元测试" << std::endl;
}

void PcapMsgTest::TearDownTestCase()
{
    std::cout << "结束PcapMsgTest单元测试" << std::endl;
}


TEST_F(PcapMsgTest,unpack_ok){
    static const unsigned char pkt38[57] = {
    0x00, 0x0c, 0x29, 0xb9, 0x8c, 0x55, 0x44, 0x1c, /* ..)..UD. */
    0xa8, 0xe2, 0x1c, 0xcd, 0x08, 0x00, 0x45, 0x00, /* ......E. */
    0x00, 0x2b, 0x1c, 0xbd, 0x40, 0x00, 0x80, 0x06, /* .+..@... */
    0x51, 0xf2, 0xc0, 0xa8, 0x05, 0x68, 0xc0, 0xa8, /* Q....h.. */
    0x05, 0x65, 0xdf, 0x53, 0xc3, 0x51, 0x7b, 0x8d, /* .e.S.Q{. */
    0x4d, 0xcc, 0x83, 0x83, 0xf6, 0x56, 0x50, 0x18, /* M....VP. */
    0x08, 0x05, 0xd1, 0x9a, 0x00, 0x00, 0x31, 0x32, /* ......12 */
    0x33                                            /* 3 */
    };

    std::shared_ptr<InetIpv4> pip(new InetIpv4);
    std::shared_ptr<InetTcp> ptcp( new InetTcp);


    PackType hexData( (uint8_t*)pkt38,57 );
    PcapMsg parser;
    parser.setInternetIp(pip.get());
    parser.setTcp(ptcp.get());

    parser.unpack(hexData);

    PackType data = parser.getApplicationData();

    std::cout << data.toString() << std::endl;

    static const unsigned char ret[3] = {
        0x31, 0x32, 0x33
    };
    PackType retPack( (uint8_t*)ret, 3 );

    ASSERT_EQ( retPack, data );
}
